<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	
<%@page import="com.lovo.bbs.vo.*,com.lovo.bbs.bo.*,java.util.*"%>

<%

    String queryPages = (String)request.getParameter("queryPage");
	if(queryPages==null||"".equals(queryPages)||"0".equals(queryPages)){
	  queryPages="1";
	}
	int queryPage=Integer.parseInt(queryPages);
	
	//论坛列表
	ArrayList<ForumVo> forumList = (ArrayList<ForumVo>) application.getAttribute("forumList");
	//采集主题列表(数据库分页)
	String asForumId = request.getParameter("forumSelect");//搜索范围
	if(asForumId==null||"".equals(asForumId)){
	    asForumId="0";//为0时将搜索所有论坛下的主题
	}
	int forumid = Integer.parseInt(asForumId);
	TopicBo topicBo = new TopicBo();
	ArrayList<TopicVo> topicList = (ArrayList<TopicVo>) topicBo.getTopics(forumid,queryPage);
	
	int topicNum =topicBo.getTopicNum(forumid);//查询指定论坛的主题数,参数为0时查询所有论坛主题总数
	
	int pageNum = (topicNum % 20 == 0) ? (topicNum / 20) : (topicNum / 20 + 1);
	Iterator it, it1;
%>
<html>
	<head>
		<link href="../../../css/admin.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../../../js/wbs_admin.js"></script>
		<script type="text/javascript">
		
		function preQuery(){
			document.frmMain.action="topicManageQueryPage.jsp";
			document.frmMain.submit();
		}
		
		function preModify(topicid,topictitle,forumid,authorname,topictime,hits,replynum,ishighlight,isbest,istop){
			document.frmMain.topicid.value=topicid;
			document.frmMain.topictitle.value=topictitle;
			document.frmMain.forumid.value=forumid;
			document.frmMain.authorname.value=authorname;
			document.frmMain.topictime.value=topictime;
			document.frmMain.hits.value=hits;
			document.frmMain.replynum.value=replynum;

			document.frmMain.ishighlight.value=ishighlight;
			document.frmMain.isbest.value=isbest;
			document.frmMain.istop.value=istop;
			
			document.frmMain.opType.value=2;
			
			document.frmMain.action="topicManageUpdatePage.jsp";
			document.frmMain.submit();
		}
		
		function preDelete(topicid,topictitle,forumid,authorname,topictime,hits,replynum,ishighlight,isbest,istop){
			document.frmMain.topicid.value=topicid;
			document.frmMain.topictitle.value=topictitle;
			document.frmMain.forumid.value=forumid;
			document.frmMain.authorname.value=authorname;
			document.frmMain.topictime.value=topictime;
			document.frmMain.hits.value=hits;
			document.frmMain.replynum.value=replynum;
			
			document.frmMain.ishighlight.value=ishighlight;
			document.frmMain.isbest.value=isbest;
			document.frmMain.istop.value=istop;
			
			document.frmMain.opType.value=3;
			
			document.frmMain.action="topicManageUpdatePage.jsp";
			document.frmMain.submit();
		}
		</script>
	</head>
	<body >
	  <form name="frmMain" method="post">
		 <table class="navigation" style="width:98%" align="center">
			<tr>
				<td>
					当前位置: 主题管理
				</td>
			</tr>
		 </table>
		 <fieldset style="width:98%" align="center">
			<table align="left">
				<tr>
					<td>
						&nbsp;
					</td>
				</tr>
			</table>
			<br>
			<table align="center">
				<tr>
					<td align="center" valign="middle">
						按照论坛查询:
						<select name="forumSelect">
							<option value="0">
								默认
							</option>
							<%	if (forumList == null) {
									forumList = new ArrayList<ForumVo>();
									System.out.println("forumList为空");
								}
								it1 = forumList.iterator();
								if (it1 != null) {
									while (it1.hasNext()) {
										ForumVo forumData = (ForumVo) (it1.next());
							%>
							<option value="<%=forumData.getForumID()%>"><%=forumData.getForumName()%></option>
							<%}}%>
						</select>
					</td>
					<td>
						<input type="button" class="button" value=" 查询 " onclick="preQuery()">
					</td>
				</tr>
			</table>
		</fieldset>
		<table border="0" cellspacing="0" cellpadding="0" width="98%"  align="center">
				<tr>
					<td>
						<table width="100%" border="0" cellspacing="0" cellpadding="4">
							<tr>
								<td id="content_bar">
									<a class="content_total">主题总数: <%=topicNum%> , 第<%=queryPage%>页 	总<%=pageNum%>页 </a>
									<%	for (int i = 1; i <= pageNum; i++) {
											if (i == queryPage) {
									%>
									<a class="content_pasges_c"><%=i%></a>
									<%} else {%>
									<a class="content_pasges_a" href="topicManageQueryPage.jsp?queryPage=<%=i%>"><%=i%></a>
									<%}}%>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table border="0" cellspacing="1" cellpadding="4" class="tableborder" style="width:100%; background-color:#CCFFFF; border:#99FFCC 0px solid">
							<tr class="header">
								<td width="20%">
									主题名
								</td>
								<td width="15%">
									所属论坛
								</td>
								<td width="10%">
									作者名
								</td>
								<td width="10%">
									发表时间
								</td>
								<td width="4%">
									点击数
								</td>
								<td width="4%">
									回复数
								</td>
								<td width="4%">
									高亮
								</td>
								<td width="4%">
									精华
								</td>
								<td width="4%">
									置顶
								</td>
								<td width="10%">
									操作
								</td>
							</tr>
							<%	if (topicList == null) {
									topicList = new ArrayList<TopicVo>();
									System.out.println("主题数据为空");
								}
								it = topicList.iterator();
								if (it != null) {
									while (it.hasNext()) {
										TopicVo topicData = (TopicVo) (it.next());
							%>
							<tr class="row">
								<td>
									<%=topicData.getTopicTitle()%>
								</td>
								<td>
									<%=topicData.getForumName()%>
								</td>
								<td>
									<%=topicData.getAuthorname()%>
								</td>
								<td>
									<%=topicData.getTopicDate()%>
								</td>
								<td>
									<%=topicData.getHits()%>
								</td>
								<td>
									<%=topicData.getPostNum()%>
								</td>
								<td>
								<%if ((topicData.isHighlight())) {%><font color="red">是</font><%} else {%>否<%}%>
								</td>
								<td>
								<%if ((topicData.isBest())) {%><font color="red">是</font><%	} else {%>否<%}%>
								</td>
								
								<td>
								<%if ((topicData.isTop())) {%><font color="red">是</font><%} else {%>否<%}%>
								</td>
								<td>
									<input type="button" value=" 修改 " class="button" onclick="preModify('<%=topicData.getTopicid()%>','<%=topicData.getTopicTitle()%>','<%=topicData.getForumid()%>','<%=topicData.getAuthorname()%>','<%=topicData.getTopicDate()%>','<%=topicData.getHits()%>','<%=topicData.getPostNum()%>','<%=topicData.isHighlight()%>','<%=topicData.isBest()%>','<%=topicData.isTop()%>','<%=topicData.isAttach()%>')">
									<input type="button" value=" 删除 " class="button" style="color:#ff0000;" onclick="preDelete('<%=topicData.getTopicid()%>','<%=topicData.getTopicTitle()%>','<%=topicData.getForumid()%>','<%=topicData.getAuthorname()%>','<%=topicData.getTopicDate()%>','<%=topicData.getHits()%>','<%=topicData.getPostNum()%>','<%=topicData.isHighlight()%>','<%=topicData.isBest()%>','<%=topicData.isTop()%>')">
								</td>
							</tr>
							<%}	}%>
						</table>
					</td>
				</tr>
			</table>
			<br>
			<input type="hidden" name="topicid" value="">
			<input type="hidden" name="topictitle" value="">
			<input type="hidden" name="forumname" value="">
			<input type="hidden" name="forumid" value="">
			<input type="hidden" name="replynum" value="">
			<input type="hidden" name="authorname" value="">
			<input type="hidden" name="topictime" value="">
			<input type="hidden" name="hits" value="">

			<input type="hidden" name="ishighlight" value="">
			<input type="hidden" name="isbest" value="">
			<input type="hidden" name="istop" value="">
			<input type="hidden" name="queryPage" value="<%=queryPage%>">
			
			<input type="hidden" name="opType" value="">
		</form>
	</body>
</html>
